﻿using MyHospital.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyHospital.BLL
{
    public class Time
    {
        MyHospitalDataContext db = new MyHospitalDataContext();
        public void deleteTime(string id)//删除一条数据
        {
            TimePart timePart = (from c in db.TimePart
                                 where c.timeId == int.Parse(id)
                                 select c).FirstOrDefault();
            db.TimePart.DeleteOnSubmit(timePart);
            db.SubmitChanges();
        }
        public bool isExitDate(string date,string doctorId)//判断插入的该行数据是否存在
        {
            TimePart timePart = (from c in db.TimePart
                                 where c.doctorId == int.Parse(doctorId) && c.date.ToString() == date
                                 select c).FirstOrDefault();
            if (timePart == null) return true;
            else return false;
        }
        public void insertTime(string doctorId,string time,string number,DateTime date)//插入新数据
        {
            var timePart = new TimePart();
            timePart.doctorId = int.Parse(doctorId);
            timePart.time = time;
            timePart.number = int.Parse(number);
            timePart.date =date;
            db.TimePart.InsertOnSubmit(timePart);
            db.SubmitChanges();
        }
        public void deleteAllTime(string date,string doctorId)
        {
            var timePart = (from c in db.TimePart
                            where c.date.ToString() == date&& c.doctorId==int.Parse(doctorId)
                            select c);
            db.TimePart.DeleteAllOnSubmit(timePart);
            db.SubmitChanges();
        }
    }
}
